<!DOCTYPE html>
<html>
<head>
	<title>表单Form</title>
	<link rel="stylesheet" type="text/css" href="../bootstrap/css/bootstrap.min.css">

</head>
<body>
	<div ng-app="app" style="margin-top: 20px;">
		<div class="container">
			<form name="form" action="register.action" class="form-horizontal" ng-controller="firstController">
				<div class="form-group" ng-class="{'has-error':form.username.$touched && form.username.$invalid}">
					<label class="col-sm-2 control-label">用户名</label>
					<div class="col-sm-10">
						<input type="text" name="username"	class="form-control" placeholder="请输入用户名" ng-model="data.username" ng-required="true" ng-minlength="3" ng-maxlength="10" ng-pattern="/^[a-zA-Z]{1,}/" autocomplete="off" />

						<div ng-show="form.username.$touched && form.username.$error.maxlength" class="alert alert-danger help-block">
							<p>用户名长度不能超过10！</p>
						</div>
						<div ng-show="form.username.$touched && form.username.$error.minlength" class="alert alert-danger help-block">
							<p>用户名长度不少于3位！</p>
						</div>
						<div ng-show="form.username.$touched && form.username.$error.pattern" class="alert alert-danger help-block">
							<p>用户名必须以a-zA-z开始！</p>
						</div>
					</div>
				</div>

				<div class="form-group" ng-class="{'has-error':form.password.$touched && form.password.$invalid}">
					<label class="col-sm-2 control-label">密 码</label>
					<div class="col-sm-10">
						<input type="password" name="password"	class="form-control" placeholder="请输入密码" ng-model="data.password" ng-required="true" ng-minlength="5" ng-maxlength="10"  autocomplete="off" />

						<div ng-show="form.password.$touched && form.password.$error.maxlength" class="alert alert-danger help-block">
							<p>密码长度不能超过10！</p>
						</div>
						<div ng-show="form.password.$touched && form.password.$error.minlength" class="alert alert-danger help-block">
							<p>密码长度不少于5位！</p>
						</div>
					</div>
				</div>

				<div class="form-group" ng-class="{'has-error':form.passwordConfirm.$touched && form.passwordConfirm.$invalid}">
					<label class="col-sm-2 control-label">确认密码</label>
					<div class="col-sm-10">
						<input type="password" name="passwordConfirm" class="form-control" placeholder="请输入确认密码" ng-model="data.passwordConfirm" ng-required="true" autocomplete="off" />

						<div ng-show="form.passwordConfirm.$touched && form.password.$touched && form.passwordConfirm.$touched && data.password !== data.passwordConfirm" class="alert alert-danger help-block">
							<p>确认密码与密码不一致！</p>
						</div>
					</div>
				</div>

				<div class="form-group" ng-class="{'has-error':form.email.$touched && form.email.$invalid}">
					<label class="col-sm-2 control-label">邮箱</label>
					<div class="col-sm-10">
						<input type="email" name="email" class="form-control" placeholder="请输入邮箱" ng-model="data.email" ng-required="true" autocomplete="off" ng-minlength="10" ng-maxlength="30"/>

						<div ng-show="form.email.$touched && form.email.$touched && form.email.$error.minlength" class="alert alert-danger help-block">
							<p>邮箱长度不少于10位！</p>
						</div>
						<div ng-show="form.email.$touched && form.email.$touched && form.email.$error.maxlength" class="alert alert-danger help-block">
							<p>邮箱长度不超过30位！</p>
						</div>
						<div ng-show="form.email.$touched && form.email.$touched && form.email.$error.email" class="alert alert-danger help-block">
							<p>邮箱格式不正确！</p>
						</div>
					</div>
				</div>

				<div class="form-group" ng-class="{'has-error':form.blog.$touched && form.blog.$invalid}">
					<label class="col-sm-2 control-label">博客地址</label>
					<div class="col-sm-10">
						<input type="url" name="blog" class="form-control" placeholder="请输入博客地址" ng-model="data.blog" ng-required="true" autocomplete="off" ng-minlength="10" ng-maxlength="30"/>

						<div ng-show="form.blog.$touched && form.blog.$touched && form.blog.$error.minlength" class="alert alert-danger help-block">
							<p>邮箱长度不少于10位！</p>
						</div>
						<div ng-show="form.blog.$touched && form.blog.$touched && form.blog.$error.maxlength" class="alert alert-danger help-block">
							<p>邮箱长度不超过30位！</p>
						</div>
						<div ng-show="form.blog.$touched && form.blog.$touched && form.blog.$error.url" class="alert alert-danger help-block">
							<p>博客地址格式不正确！</p>
						</div>
					</div>
				</div>

				<div class="form-group" ng-class="{'has-error':form.age.$touched && form.age.$invalid}">
					<label class="col-sm-2 control-label">年龄</label>
					<div class="col-sm-10">
						<input type="number" name="age" class="form-control" placeholder="请输入年龄" ng-model="data.age" ng-required="true" autocomplete="off" min="1" max="99"/>
						<div ng-show="form.age.$touched && form.age.$touched && form.age.$error.min" class="alert alert-danger help-block">
							<p>年龄不低1岁！</p>
						</div>
						<div ng-show="form.age.$touched && form.age.$touched && form.age.$error.maxlength" class="alert alert-danger help-block">
							<p>年龄不超过99位！</p>
						</div>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-2 control-label">性别</label>
					<div class="col-sm-10">
						<label class="radio-inline">
							<input type="radio" name="gender" ng-model="data.gender" value="1" />男
						</label>
						<label class="radio-inline">
							<input type="radio" name="gender" ng-model="data.gender" value="0" />女
						</label>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-2 control-label">爱好</label>
					<div class="col-sm-10">
						<label class="checkbox-inline" ng-repeat="hobby in hobbies">
							<input type="checkbox" name="hobby[]" value="{{hobby.id}}" ng-click="toggleSelection(hobby.id);" ng-checked="data.hobbyIds.indexOf(hobby.id) !== -1"/>{{hobby.name}}
						</label>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-2 control-label">出生地</label>
					<div class="col-sm-3">
						<select class="form-control" ng-model="data.province" ng-options="city.id as city.name for city in cities | cityFilter:{parent:0}"></select>
					</div>
					<div class="col-sm-3">
						<select class="form-control" ng-show="data.province" ng-model="data.area" ng-options="city.id as city.name for city in cities | cityFilter:{parent:data.province}"></select>
					</div>
					<div class="col-sm-3">
						<select class="form-control" ng-required="true" ng-show="data.province && data.area" ng-model="data.city" ng-options="city.id as city.name for city in cities | cityFilter:{parent:data.area}"></select>
					</div>
				</div>

				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="submit" class="btn btn-primary" ng-disabled="form.$invalid || data.city === undefine || data.hobbyIds.length === 0">注册</button>
						<button type="reset" class="btn btn-danger" ng-click="reset();">重置</button>
					</div>
				</div>
			</form>
		</div>

	</div>

	<script type="text/javascript" src="../angular/angular-1.6.5.min.js"></script>
	<script type="text/javascript" src="app/index.js"></script>
</body>
</html>